package com.currency.mall.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.currency.mall.R;
import com.currency.mall.entity.OrderInfo;
import com.currency.mall.util.Util;

import java.util.List;

/**
 * Created by Administrator on 2018/12/5.
 */

public class OrderBalanceAdapter extends BaseQuickAdapter<OrderInfo, BaseViewHolder> {

    public OrderBalanceAdapter(@Nullable List<OrderInfo> data, Context context) {
        super(R.layout.item_order_balance, data);
    }

    @Override
    protected void convert(BaseViewHolder helper,OrderInfo orderInfo) {
        helper.addOnClickListener(R.id.iv_current_state);
        helper.setText(R.id.tv_bid_name,orderInfo.getSharesName()+" ("+orderInfo.getSharesCode()+" )");
        helper.setText(R.id.tv_start_time,orderInfo.getBeginTime().substring(0,10));
        helper.setText(R.id.tv_end_time,orderInfo.getEndTime().substring(0,10));
        if(TextUtils.isEmpty(orderInfo.getEntrustCloseTime())){
            helper.setText(R.id.tv_expire_time,"————");
        }else {
            helper.setText(R.id.tv_expire_time,orderInfo.getEntrustCloseTime().substring(0,10));
        }
        if(TextUtils.isEmpty(orderInfo.getEndSum())){
            helper.setText(R.id.tv_end_tranche_profit,"————");
        }else {
            helper.setText(R.id.tv_end_tranche_profit,orderInfo.getEndSum());
        }
        if(TextUtils.isEmpty(orderInfo.getProfitMoney())){
            helper.setText(R.id.tv_balance_profit,"————");
        }else {
            helper.setText(R.id.tv_balance_profit,Util.formatTosepara(Double.parseDouble(orderInfo.getProfitMoney())));
        }

        if("DAY".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"天");
        }else  if("WEEK".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"周");
        }else  if("MONTH".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"月");
        }
        ImageView imageView = helper.getView(R.id.iv_current_state);

        if("WAIT_CLOSE".equals(orderInfo.getStatus())){
            helper.setText(R.id. tv_current_state,"等待结算");
            imageView.setVisibility(View.GONE);
        }else if("IN_CLOSE".equals(orderInfo.getStatus())){
            helper.setText(R.id. tv_current_state,"结算中");
            imageView.setVisibility(View.VISIBLE);
        }else if("CLOSE".equals(orderInfo.getStatus())){
            helper.setText(R.id. tv_current_state,"已结算");
            imageView.setVisibility(View.GONE);
        }
        helper.setText(R.id.tv_nominal_principal, Util.formatTosepara(Double.parseDouble(orderInfo.getNameSum())));
        helper.setText(R.id.tv_start_tranche_price,orderInfo.getBeginSum());
        helper.setText(R.id.tv_rightSum,Util.formatTosepara(Double.parseDouble(orderInfo.getRightSum())));


    }

}
